package com.music.authority.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.music.authority.dao.UpVedioDao;
import com.music.domain.Music;
import com.music.domain.Video;

/**
 * 实现类
 * @author LFSenior
 *
 */
@Repository
public class UpVedioDaoImpl implements UpVedioDao {

	@Autowired
	SessionFactory sessionFactory;
	
	@Override
	public void insertVedio(Map param) {
		String sql="INSERT INTO T_VIDEO(ID,NAME,IMGURI,VIDEOURI,AUTHOR) VALUES("
				+ ":ID,:NAME,:IMGURI,:VIDEOURI,:AUTHOR)";
		SQLQuery sqlQuery = sessionFactory.getCurrentSession().createSQLQuery(sql);
		sqlQuery.setParameter("ID", param.get("id"));
		sqlQuery.setParameter("NAME", param.get("name"));
		sqlQuery.setParameter("IMGURI", param.get("imguri"));
		sqlQuery.setParameter("VIDEOURI", param.get("videouri"));
		sqlQuery.setParameter("AUTHOR", param.get("author"));
		sqlQuery.executeUpdate();
	}

	@Override
	public void deleteVedio(String VedioId) {
		Session session = sessionFactory.getCurrentSession();
		session.delete(session.get(Video.class, VedioId));
	}

	@Override
	public List<Video> findAllVedio() {
		String hql="from Video";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		List<Video> data = query.list();
		return data;
	}

}
